/*
 * Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 * This file is part of e3lock.
 *
 * e3lock is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * e3lock is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with e3lock. If not, see <https://www.gnu.org/licenses/>.
 */

package e3lock

import (
	"fmt"
	"github.com/fatih/color"
	"os"
	"time"
)

var (
	traceColor = color.New(color.FgHiCyan)
	warnColor  = color.New(color.FgHiCyan)
)

type Logger interface {
	TracePrintf(format string, args ...any)
	WarnPrintf(format string, args ...any)
}

func SetLogger(l Logger) {
	_gLogger = l
}

var (
	_gLogTrace bool   = false
	_gLogger   Logger = nil
)

func init() {
	_gLogger = &logger{}
}

type logger struct {
}

func (ts *logger) TracePrintf(format string, args ...any) {
	_, _ = fmt.Fprintf(os.Stdout, logFormat, time.Now().Format(layout), traceColor.Sprint(traceFormat), traceColor.Sprintf(format, args...))
}

func (ts *logger) WarnPrintf(format string, args ...any) {
	_, _ = fmt.Fprintf(os.Stdout, logFormat, time.Now().Format(layout), warnColor.Sprint(warnFormat), warnColor.Sprintf(format, args...))
}
